﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.CompilerServices;
using DAL.DataFramework;

[assembly: InternalsVisibleTo("BE")]
namespace BE.DataFramework
{    
    public class ConnectorsBE
    {
        public int? iConnectorId { get; set; }
        public string sConnectorName { get; set; }
        public bool bActive { get; set; }

        internal ConnectorsBE Create()
        {
            try
            {
                ConnectorsBE result = new ConnectorsBE();
                using (ConnectorsDAL<ConnectorsBE> datos = new ConnectorsDAL<ConnectorsBE>())
                {
                    result = datos.Create(this.sConnectorName);

                }
                return result;
            }
            catch (Exception ex)
            {
                throw new Exception("ConnectorsBE - Create - ", ex);
            }
        }
        internal ConnectorsBE Update(int iConnectorId, string sConnectorName, bool bActive)
        {
            try
            {
                ConnectorsBE result = new ConnectorsBE();
                using (ConnectorsDAL<ConnectorsBE> datos = new ConnectorsDAL<ConnectorsBE>())
                {
                    result = datos.Update(
                        (int)this.iConnectorId, 
                        this.sConnectorName, 
                        this.bActive);

                }
                return result;
            }
            catch (Exception ex)
            {
                throw new Exception("ConnectorsBE - Update - ", ex);
            }
        }
        internal bool Delete()
        {
            try
            {
                bool result = false;
                using (ConnectorsDAL<ConnectorsBE> datos = new ConnectorsDAL<ConnectorsBE>())
                {
                    result = datos.Delete(
                        (int)this.iConnectorId);

                }
                return result;
            }
            catch (Exception ex)
            {
                throw new Exception("ConnectorsBE - Update - ", ex);
            };
        }
        internal bool ExistConnectorName()
        {
            return true;
        }
        internal bool ExistsConnectorId()
        {
            return true;
        }
        internal List<ConnectorsBE> Select()
        {
            List<ConnectorsBE> result = new List<ConnectorsBE>();

            try
            {
                ConnectorsDAL<ConnectorsBE> connector = new ConnectorsDAL<ConnectorsBE>();

                result = connector.Select(
                    this.iConnectorId == null ? -1 : (int)this.iConnectorId,
                    this.sConnectorName,
                    this.bActive);

                return result;
            }
            catch (Exception ex)
            {
                throw new Exception("", ex);
            }
        }
    }

}
